package com.book.controller;

import com.book.service.BookService;
import com.commons.entity.Book;
import com.commons.entity.ResultFul;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/book")
public class BookController {
    @Resource
    BookService bookService;

    /**
     * 用于直接查询书籍信息的接口
     * @param bid
     * @return
     */
    @GetMapping("{bid}")
    public ResultFul findBookById(@PathVariable("bid") Integer bid){
        return bookService.findByBid(bid);
    }

    /**
     *  用于间接 接口内部调用去获取用户信息的接口
     * @param bid
     * @return
     */
    @GetMapping("api/{bid}")
    public Book apiFindBookById(@PathVariable("bid") Integer bid){
        return (Book) bookService.findByBid(bid).getData();
    }
}
